﻿using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using JoeyLibs.Utility;

namespace JoeyLibs.Utility.Log
{
    /// <summary>
    /// 错误与异常的日志实体
    /// </summary>
    public class ExceptionLogModel : LogModel
    {
        private Exception exception;
        /// <summary>
        /// 相关异常对象
        /// </summary>
        public Exception Exception
        {
            get { return exception; }
            set { this.exception = value; }
        }

        protected override ILog Log
        {
            get
            {
                return GetLogger("ErrorLogger");
            }
        }

        public ExceptionLogModel(string message = "", string reason = "", string solution = "", Exception exception = null)
            : base(message)
        {
            base.Reason = reason;
            base.Solution = solution;
            this.exception = exception;
        }

        public override void Output()
        {
            string outMsg = LogUtility.GetLogMessage(this);
            if (exception != null)
            {
                Log.Error(outMsg.InsertLast(string.Format("Exception: {0}", exception.ToString())));
                //Log.Error(string.Empty, exception);
            }
            else if (exception == null)
            {
                Log.Error("当前日志不是一个异常或错误");
            }
            //else
            //{
            //    Log.Error(outMsg);
            //}
        }
    }
}
